<template>
  <div class="profile">
    <header>
      <!-- 头部背景图片 -->
      <div class="back"></div>
    </header>
    <main>
      <div class="card">
        <!-- 头像 -->
        <h1>
          <img
            src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F202005%2F23%2F20200523151414_gmqxe.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631879366&t=713ad2c9422ee32c4c37cc8b1840571d"
            alt=""
          />
        </h1>
        <div class="con">
          <!-- 判断用户是否登录 -->
          <p v-if="username">
            <span>{{ username }}</span>
            <button @click="exit">退出</button>
          </p>
          <p v-else>
            <span>游客</span>
            <button @click="goLogin">去登录</button>
          </p>
        </div>
      </div>
      <!-- 主体图表内容区 -->
      <div class="icons">
        <a href="/rent">
          <div class="rend">
            <i class="iconfont icon-shouye"></i>
            <span>我的出租</span>
          </div>
        </a>
        <a href="">
          <div class="rend">
            <i class="iconfont icon-shizhong1"></i>
            <span>看房记录</span>
          </div>
        </a>
        <a href="">
          <div class="rend">
            <i class="iconfont icon-gongzuojilu"></i>
            <span>成为房主</span>
          </div>
        </a>
        <a href="">
          <div class="rend">
            <i class="iconfont icon-wode"></i>
            <span>个人资料</span>
          </div>
        </a>
        <a href="">
          <div class="rend">
            <i class="iconfont icon-kefu"></i>
            <span>联系我们</span>
          </div>
        </a>
      </div>
      <div class="foot_img">
        <img
          src="https://api-haoke-web.itheima.net/img/profile/join.png"
          alt=""
        />
      </div>
      <!-- 退出登录提示弹窗 :before-close="beforeClose"-->
      <van-dialog
        v-model="show"
        title="提示"
        message="是否确认退出？"
        show-cancel-button
      >
      </van-dialog>
    </main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 获取本地的username属性
      username:localStorage.getItem("username"),
      show: false,
    }
  },
  methods: {
    /// 跳转登录页面
    goLogin() {
      this.$router.push("/login");
    },
    /// 退出清除用户名
    exit() {
      localStorage.setItem("username", "");
      this.username = localStorage.getItem("username");
      this.show = !this.show;
    },
  }
};
</script>

<style lang='scss' scoped>
.profile {
  width: 100%;
  height: 100%;
  overflow: hidden;
  header .back {
    width: 125%;
    height: 4.8rem;
    border-radius: 0 0 50% 50%;
    transform: translate(-10%, -20%);
    background-color: #f3c5c5;
    position: absolute;
    top: 0;
    background-image: url("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.doubanio.com%2Fview%2Fgroup_topic%2Fl%2Fpublic%2Fp424117867.jpg&refer=http%3A%2F%2Fimg1.doubanio.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1631878918&t=e48b7f8a2fa498b11b1c034feb304154");
    background-size: 100% 3.8rem;
  }
}
main {
  width: 100%;
  height: 3.8rem;
}
.card {
  position: absolute;
  background: #fff;
  width: 85%;
  height: 25%;
  top: 1rem;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  box-shadow: 0 0 0.2rem 0.06rem #ddd;
  margin: 1rem auto 0;
  padding: 0 0.4rem;
  text-align: center;
  font-size: 13px;
  h1 {
    position: relative;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
    border-radius: 50%;
    width: 1.5rem;
    height: 1.5rem;
    border: 5px solid #f5f5f5;
    display: inline-block;
    box-shadow: 0 0.04rem 0.04rem #bdbdbd;
    img {
      width: 100%;
      border-radius: 50%;
    }
  }
  .con {
    padding-top: 0.3rem;
    p {
      margin-top: -0.45rem;
      margin-bottom: 0.55rem;
      button {
        display: block;
        border-radius: 30px;
        color: #fff;
        padding: 2px 15px;
        background: #21b97a;
        margin: 0 auto;
        outline: none;
        border: none;
      }
    }
  }
}
.icons {
  margin-top: 5.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  a {
    flex-shrink: 0;
    height: 1.9rem;
    width: calc(100% / 3);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 15px;
    color: #333;
    text-align: center;
    margin: 0.1rem 0;
    .rend {
      i {
        display: block;
        font-size: 20px;
        margin-bottom: 10px;
      }
    }
  }
}
.foot_img {
  text-align: center;
  margin-top: 10px;
  img {
    width: 92%;
  }
}
</style>